//
//  InformationRootViewController.m
//  gamebox_qpp
//
//  Created by 赵隆杰 on 2021/12/10.
//

#import "InformationRootViewController.h"
#import "InformationPageViewController.h"
#import "InformationTypeListApi.h"

#import "InformationViewModel.h"
#import "InformationScrollView.h"
#import "InformationTopView.h"
#import "InformationPageViewController.h"

@interface InformationRootViewController ()

@property(nonatomic,strong) InformationViewModel *viewModel;
@property (nonatomic, strong) InformationScrollView *scrollView;
@property (nonatomic, strong) InformationTopView *topView;
@property (nonatomic, strong) InformationPageViewController *pageVc;
@end

@implementation InformationRootViewController

-(InformationViewModel *)viewModel
{
    if (!_viewModel) {
        _viewModel = [[InformationViewModel alloc] init];
    }
    return _viewModel;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.centerTitle.text = @"我的游戏";
    
    self.scrollView = [[InformationScrollView alloc] init];
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.mas_equalTo(UIDevice.vg_navigationFullHeight);
        make.bottom.mas_equalTo(-UIDevice.vg_tabBarFullHeight);
    }];
    UIView *scrollContentView = [[UIView alloc] init];
    [self.scrollView addSubview:scrollContentView];
    [scrollContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.centerX.equalTo(self.scrollView);
    }];
    
//    self.topView = [[InformationTopView alloc] initWithFrame:CGRectMake(0, 0, SL_WINDOW_WIDTH, [InformationTopView height])];
//    [scrollContentView addSubview:self.topView];
    
    [self requestData:scrollContentView];
    
    
}

- (void)requestData:(UIView *)scrollContentView
{
    // 请求头部数据
    VHWeakSelf
    [self.viewModel fetchInitData:^{
        VHStrongSelf
//        self.topView.viewModel = self.viewModel;
        
        self.pageVc = [[InformationPageViewController alloc] initWithClassiifys:self.viewModel.types];
        [self addChildViewController:self.pageVc];
        [self.view addSubview:self.pageVc.view];
        [self.pageVc.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(scrollContentView).offset(0);
            make.left.equalTo(scrollContentView).offset(0);
            make.right.equalTo(scrollContentView).offset(0);
            make.bottom.equalTo(scrollContentView);
            make.height.mas_equalTo(SL_WINDOW_HEIGHT - UIDevice.vg_navigationFullHeight - UIDevice.vg_tabBarFullHeight);
        }];
    }];
    
}


@end
